Skip to content

fix: encode spaces as %20 in query parameters instead of + - #710

Open
themanoj-025 wants to merge 1 commit into
pinecone-io:mainfrom
themanoj-025:fix/query-param-space-encoding
Open

themanoj-025 wants to merge 1 commit into
pinecone-io:mainfrom
themanoj-025:fix/query-param-space-encoding

Conversation

@themanoj-025

@themanoj-025 themanoj-025 commented Nov 28, 2026 •

Copy link
Copy Markdown

Fixes #705

Problem

In v9+, after transitioning to httpx, requests with query parameters (such as /vectors/fetch, /vectors/list, and /namespaces) converted spaces in IDs or namespaces to + rather than %20 (regression of #372). Because Pinecone treats + as a literal character, passing IDs or namespaces containing spaces (e.g. doc 42, my namespace) resulted in empty results or missing records.

Root Cause

httpx encodes query parameters using urllib.parse.urlencode with its default quote_via=quote_plus, converting spaces to +. When passing query parameters via params=... to httpx.Client or httpx.AsyncClient, httpx internally re-encodes query parameters using quote_plus.

Solution

  1. Added _encode_query_params in pinecone/_internal/http_client.py using urllib.parse.urlencode(..., doseq=True, quote_via=urllib.parse.quote) so spaces are RFC 3986 percent-encoded as %20 and literal plus signs are encoded as %2B.
  2. Updated _prepare_path_and_kwargs to merge encoded query parameters directly onto the request path, preserving %20 on the wire for both sync (HTTPClient) and async (AsyncHTTPClient) methods.
  3. Added comprehensive regression tests in tests/unit/test_query_param_spaces_705.py covering:
    • Sync GET with multiple vector IDs containing spaces, plus signs, and hyphens (ids=doc%2042&ids=doc%2B42).
    • Sync DELETE with namespace containing spaces.
    • Async GET and DELETE with spaces.
    • Verified backward compatibility with existing enum resolution and parameter tests (test_query_param_enums_371.py).

Note

Medium Risk
Touches the central HTTP client request path for all REST calls with query parameters; behavior change is intentional but affects every endpoint that passes params=.

Overview
Fixes a regression where httpx sent query values with spaces as +, while Pinecone treats + literally—so fetch/list/delete on namespaces or vector IDs containing spaces (e.g. doc 42) could return nothing (#705).

The HTTP layer now RFC 3986-encodes query parameters with %20 for spaces (and %2B for literal plus signs) via new _encode_query_params, then appends that string to the request path through _prepare_path_and_kwargs instead of handing params= to httpx (which re-encodes with quote_plus). Sync and async get/put/patch/delete and the POST slow path use this flow; enum resolution for params is preserved inside the encoder.

Adds tests/unit/test_query_param_spaces_705.py to assert the on-the-wire path for sync/async GET and DELETE with spaced namespaces and mixed ids.

Reviewed by Cursor Bugbot for commit 94293e4. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Manoj Jana <jm2705470@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Spaces in IDs and namespaces sent as "+" in GET requests since 9.0.0 (regression of #372)

1 participant